#pragma once

#include "Serializable.h"
#include "Vectors.h"

class ServiceProvider;

struct TeamScore
{
	void Serialize(ZStream& o_stream) const;
	void Deserialize(ZStream& i_stream);

	int		m_teamID;		//teamID
	size_t	m_score;		//punti
	size_t	m_winMatches;	//partite vinte
	size_t	m_lostMatches;	//partite perse
	size_t	m_drawMathes;	//partite pareggiate
	size_t	m_inGoals;		//goal subiti
	size_t	m_outGoals;		//goal fatti
};
typedef STL::vector<TeamScore>	TeamScoreCollection;

class Classification : public Serializable
{
public:
	explicit Classification(ServiceProvider* i_sp);
	~Classification();

	void Clear();
	void Initialize(const TeamVec& i_teams);
	void Update(const MatchDataVec& i_matchScore);

	void GetSortedTeams(TeamVec& o_teams) const;
	const MatchDataVec&	GetMatchesHistory() const;

	const TeamScoreCollection& GetTeamScores() const;

	virtual	ZStream& Serialize(ZStream& o_stream) const;
	virtual ZStream& Deserialize(ZStream& i_stream);

private:
	//copy disabled
	Classification(const Classification&);
	Classification& operator=(const Classification&);

	struct CompareTeamID
	{
		CompareTeamID(const int i_teamID) : m_id(i_teamID){}
		bool operator() (const TeamScore& i_score) const
		{
			return (m_id == i_score.m_teamID);
		}
		int m_id;
	};

	TeamScoreCollection	m_teamScores;
	MatchDataVec		m_matchHistory;
	ServiceProvider*	m_sp;
};

inline const MatchDataVec& Classification::GetMatchesHistory() const
{
	return m_matchHistory;
}

inline const TeamScoreCollection& Classification::GetTeamScores() const
{
	return m_teamScores;
}
